{include file="common/header"/}
<style>
    .layui-form-item .layui-input-inline{
        width: 500px;
    }
</style>
<div class="lemo-container">
    <div class="lemo-main">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>{$title}</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" lay-filter="form">

            <div class="layui-form-item">
                <label class="layui-form-label">环节名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="required" readonly class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">文档上传</label>
                <input type="hidden" name="upfile" id="upfile">
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-primary" data-type="file" data-path="schedule" id="uploads-file"><i class="icon icon-upload3"></i>点击上传</button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-form-text" style="width: 610px">
                <label class="layui-form-label">心得体会</label>
                <div class="layui-input-block">
                                    <textarea name="feelings" class="layui-textarea"
                                              placeholder="心得体会"></textarea>
                </div>
            </div>

            <div class="layui-form-item layui-form-text" style="width: 610px">
                <label class="layui-form-label">老师评价</label>
                <div class="layui-input-block">
                                    <textarea name="evaluate" readonly class="layui-textarea"
                                              placeholder="评价"></textarea>
                </div>
            </div>

<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label">题目名称</label>-->
<!--                <div class="layui-input-inline">-->
<!--                    <textarea type="text" name="username" lay-verify="required" placeholder="{:lang('pleaseEnter')}描述" >-->
<!--                </div>-->
<!--            </div>-->

            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" name="id"  >
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                    <a data-href="{:url('index')}" class="layui-btn layui-btn-primary back">{:lang('back')}</a>
                </div>
            </div>
        </form>
    </div>
</div>

{include file="common/footer"/}
<script>
    layui.config({
        base: "/static/admin/js/",
        version: true
    }).extend({
        Admin:'Admin',
    }).use(['Admin','form','laydate', 'upload'], function () {
        var form = layui.form, laydate=layui.laydate ,upload = layui.upload,$=layui.$;
        var info = '';
        //日期范围
        laydate.render({
            elem: '#date'
            ,range: true
        });

        info = {:json_encode($info)};
        form.val("form", info);
        if(info){
            $('#addPic').attr('src',info.avatar);
        }
        form.render();

        /* 成功
            * @param title
            * @returns {*}
        */

        function success (title) {
            layer.msg(title, {icon: 1, shade: this.shade, scrollbar: false, time: 2000, shadeClose: true});
        };

        /**
         * 失败
         * @param title
         * @returns {*}
         */

        function error(title) {
            layer.msg(title, {icon: 2, shade: this.shade, scrollbar: false, time: 3000, shadeClose: true});
        };

        if($('#uploads-file')){
            // 文件上传
            var path = $('#uploads-file').attr('data-path');
            var type = $('#uploads-file').attr('data-type')
            var uploadInt = upload.render({
                elem: '#uploads-file',
                accept: 'file'
                ,url: '/admin/sys.uploads/uploads?path='+path+'&type='+type
                ,before: function(obj){
                    layer.load()
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#addPic').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    if(res.code>0){
                        $('#upfile').val(res.url);
                        //如果上传失败
                        layer.closeAll()
                        return success('上传成功');
                    }else{
                        //如果上传失败
                        return error('上传失败');
                    }
                }
                ,error: function(){
                    layer.closeAll()
                    //演示失败状态，并实现重传
                    var notice = $('#notice');
                    notice.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    notice.find('.demo-reload').on('click', function(){
                        uploadInt.upload();
                    });
                }
            });
        }

    });
</script>